library(tidyverse)
library(plotly)
library(p8105.datasets)
data("nyc_airbnb")
nyc_airbnb =
nyc_airbnb %>%
mutate(
rating = review_scores_location /2
) %>%
select(
neighbourhood_group, neighbourhood, rating, price, room_type, lat, long
) %>%
filter(
neighbourhood_group == "Manhattan",
room_type == "Entire home/apt",
price <= 500,
price >= 100
)
let’s make a scatterplot - but interactive… note:
type = "scatter", mode = "markers" aka a scatterplot note:
"\nRating: ", rating that backslash + n allows you to name
a new line for your label
nyc_airbnb %>%
mutate(
label = str_c("Price: $", price, "\nRating: ", rating)
) %>%
plot_ly(
x = ~lat, y = ~long, color = ~price,
text = ~label,
type = "scatter", mode = "markers", alpha = 0.5
)